package com.tvsinfo.jdk.demo.case1_grammar;

/**
 * 行为参数化-线程实例
 */
public class RunableDemo {


    public static void main(String[] args) {

        //默认匿名内部类
        Runnable runnable1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("starting1 .......");
                try {
                    Thread.sleep(3000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("end1 .......");
            }
        };

        Thread thread = new Thread(runnable1);
        thread.start();

        //行为参数化
        Runnable runnable = () -> {
            System.out.println("starting2 .......");
            try {
                Thread.sleep(3000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("end2 .......");
        };

        Thread thread2 = new Thread(runnable);
        thread2.start();
    }
}
